(() => {

    // 定义一个字符串数组
    // let sites: string[];
    let sites: Array<string>;
    // 初始化，赋值
    sites = ["Google", "Runoob", "Taobao"]
    console.log(sites[0]);
    console.log(sites[1]);
    console.log(sites[2]);


    // 另一种方式，定义一个数组
    var arr_names: number[] = new Array(4)

    // 循环迭代赋值
    for (var i = 0; i < arr_names.length; i++) {
        arr_names[i] = i * 2
        console.log(arr_names[i])
    }


    // 数组解构
    let arr: number[] = [12, 13]
    var [x, y] = arr // 将数组的两个元素赋值给变量 x 和 y
    console.log(x)
    console.log(y)

    // 数组迭代
    let j: any;
    var nums: number[] = [1001, 1002, 1003, 1004]
    for (j in nums) {
        console.log(nums[j])
    }

    // forEach 迭代
    nums.forEach(value => {
        console.log(value)
    })

    let num = [7, 8, 9];
    num.forEach(function (value) {
        console.log(value);
    });

    // map 函数
    num = num.map(Math.sqrt);

    num.forEach(v => {
        console.log(v);
    })


    // push pop
    let numbers = new Array(1, 4, 9);
    let length = numbers.push(10);
    console.log("new numbers is : " + numbers);  // 1,4,9,10 
    length = numbers.push(20);
    console.log("new numbers is : " + numbers);  // 1,4,9,10,20

    numbers.pop()
    console.log("new numbers is : " + numbers);  // 1,4,9,10

    numbers.pop()
    console.log("new numbers is : " + numbers);  // 1,4,9

})()